/**
  ******************************************************************************
  * @file    mathx_fit.h
  * @author  siyun.chen
  * @version v1.0.0
  * @date
  * @brief   适用于嵌入式端的C语言数学拓展库
  ******************************************************************************
  * Change Logs:
  * 2025-07-30      siyun.chen      first version
  ******************************************************************************
  *
  * MIT License
  *
  * Copyright (c) 2025 siyun.chen
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  ******************************************************************************
  */
#ifndef _mathx_FIT_H
#define _mathx_FIT_H

/**
 * @brief  一阶多项式最小二乘拟合（y=kx+b）
 * @param  x    输入数据点x轴数组
 * @param  y    输入数据点y轴数组
 * @param  n    数据点数量（n ≥ 2）
 * @param  k    输出参数：斜率k
 * @param  b    输出参数：截距b
 * @param  r2   输出参数：决定系数R²（可为NULL，为NULL时不计算决定系数）
 * @retval 0    成功
 * @retval -1   失败，参数错误或计算不稳定
 */
int mathx_fit_linear_f32(float *x, float *y, int n, float *k, float *b, float *r2);

/**
 * @brief  二阶多项式最小二乘拟合（y=ax²+bx+c）
 * @param  x    输入数据点x轴数组
 * @param  y    输入数据点y轴数组
 * @param  n    数据点数量（n ≥ 3）
 * @param  a    输出参数：二次项系数
 * @param  b    输出参数：一次项系数
 * @param  c    输出参数：常数项
 * @param  r2   输出参数：决定系数R²（可为NULL，为NULL时不计算决定系数）
 * @retval 0    成功
 * @retval -1   失败，参数错误或计算不稳定
 */
int mathx_fit_quadratic_f32(float *x, float *y, int n, float *a, float *b, float *c, float *r2);

#endif
